
Imports cmplib01
Imports System.IO
Imports System.Drawing.Graphics


Public Class frmNewEmptyCampaign
    Inherits System.Windows.Forms.Form

    Private ptrCGD As cmplib01.CampaignerGameData
    Private mClassTypes() As String
    Private mCancelPressed As Boolean

    Private _fmpDisp As FMPLib01.FlexMapData

    Friend WithEvents btnSep3 As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnView As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
    Friend WithEvents chkOOBOnly As System.Windows.Forms.CheckBox
    Friend WithEvents lblMBGPV As System.Windows.Forms.Label
    Friend WithEvents btnFastEdit As System.Windows.Forms.ToolBarButton
    Friend WithEvents chkHaltOnNewDetection As System.Windows.Forms.CheckBox
    Friend WithEvents btnOpenTemplate As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSaveTemplate As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSepies As System.Windows.Forms.ToolBarButton
    Friend WithEvents lblCombatRange As System.Windows.Forms.Label
    Friend WithEvents numCombatRange As System.Windows.Forms.NumericUpDown
    Friend WithEvents btnAddOrder As System.Windows.Forms.ToolBarButton
    Friend WithEvents cmIndicatorOptions As System.Windows.Forms.ContextMenuStrip
    Friend WithEvents ValueIndicatorToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents NamedIndicatorToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents NamedValueIndicatorToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents numMaxBGPV As System.Windows.Forms.NumericUpDown
    Friend men As ContextMenu

    'Private selectedItemKey As String

#Region " Windows Form Designer generated code "

    Public Sub New(ByVal CGD As cmplib01.CampaignerGameData)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        ' set up the pointer
        ptrCGD = CGD
        Me.dspDefined.campaignerGameData = ptrCGD
        dspDefined.ListItems()

        'TODO Populate if we opened from file
        txtNewCampaign.Text = ptrCGD.GameName
        ' select the correct index for the drop down turn length
        cboTurnLength.SelectedIndex = CType(ptrCGD.TurnLength, String)
        txtMaxTurns.Text = ptrCGD.MaxTurns.ToString
        txtCampaignDescription.Text = ptrCGD.CampaignDescription
        chkOOBOnly.Checked = ptrCGD.ForceOOB
        numMaxBGPV.Value = ptrCGD.BattlegroupMaxPointValue
        chkUseZOC.Checked = ptrCGD.UsesZOC
        chkHaltOnNewDetection.Checked = ptrCGD.haltOnNewDetection
        chkOOBOnly.Enabled = True

        men = New ContextMenu
        men.MenuItems.Add("Value Indicator", AddressOf IndicatorMenuClicked)
        men.MenuItems.Add("Named Indicator", AddressOf IndicatorMenuClicked)
        men.MenuItems.Add("Named Value Indicator", AddressOf IndicatorMenuClicked)

        btnAddOrder.DropDownMenu = men


        Try
            numCombatRange.Value = ptrCGD.combatEngagementRange
        Catch ex As Exception
            numCombatRange.Value = 16
        End Try

#If MASTER = 1 Then
        chkDemo.Enabled = True
        '// we get this from deep within the datamap which may turn out to be completely pointless, but its one more little hurdle
        Dim obj As Object = ptrCGD.SystemValue("datamap")
        Dim demo As Boolean

        If TypeOf obj Is String Then
            demo = True
            ptrCGD.SetUpDataMapping()
        Else
            Dim datamap() As Byte = obj
            If datamap(221) = 0 Then
                demo = False
            Else
                demo = True
            End If
        End If
        chkDemo.Checked = demo
#Else
        chkDemo.Enabled = False
        chkDemo.Visible = False
        chkDemo.Checked = False
#End If

        If ptrCGD.TheaterMapFilename <> "none" Then
            Dim totalPath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\campaigns\maps\"
            OpenFMP(totalPath & ptrCGD.TheaterMapFilename)
        End If

    End Sub

    Private Sub IndicatorMenuClicked(ByVal sender As Object, ByVal args As EventArgs)
        MessageBox.Show(DirectCast(sender, MenuItem).Text)
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents CtlObjectDisplay1 As Campaigner.ctlObjectDisplay
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents dspDefined As Campaigner.ctlObjectDisplay
    Friend WithEvents tlbAddItems As System.Windows.Forms.ToolBar
    Friend WithEvents btnAddObjectiveType As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAddUnitType As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAddTokenType As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAddRule As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAddResource As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAddIndicator As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSep As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSep2 As System.Windows.Forms.ToolBarButton
    Friend WithEvents imlToolbarIcons As System.Windows.Forms.ImageList
    Friend WithEvents pnlMap As System.Windows.Forms.Panel
    Friend WithEvents lblMap As System.Windows.Forms.Label
    Friend WithEvents btnOpenMap As System.Windows.Forms.Button
    Friend WithEvents chkDemo As System.Windows.Forms.CheckBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents btnAddDeploymentZone As System.Windows.Forms.ToolBarButton
    Friend WithEvents txtNewCampaign As System.Windows.Forms.TextBox
    Friend WithEvents cboTurnLength As System.Windows.Forms.ComboBox
    Friend WithEvents btnEditFactions As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnProperties As System.Windows.Forms.Button
    Friend WithEvents btnDelete As System.Windows.Forms.Button
    Friend WithEvents txtMaxTurns As System.Windows.Forms.TextBox
    Friend WithEvents btnElementManager As System.Windows.Forms.ToolBarButton
    Friend WithEvents tabOptions As System.Windows.Forms.TabControl
    Friend WithEvents tabMap As System.Windows.Forms.TabPage
    Friend WithEvents tabGameOptions As System.Windows.Forms.TabPage
    Friend WithEvents imlTabPageImages As System.Windows.Forms.ImageList
    Friend WithEvents chkAllowPlayerManageChits As System.Windows.Forms.CheckBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents chkAllowReinforcements As System.Windows.Forms.CheckBox
    Friend WithEvents chkUseZOC As System.Windows.Forms.CheckBox
    Friend WithEvents lblMapWidth As System.Windows.Forms.Label
    Friend WithEvents lblMapheight As System.Windows.Forms.Label
    Friend WithEvents tabDescription As System.Windows.Forms.TabPage
    Friend WithEvents txtCampaignDescription As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNewEmptyCampaign))
        Me.btnOK = New System.Windows.Forms.Button
        Me.tlbAddItems = New System.Windows.Forms.ToolBar
        Me.btnOpenTemplate = New System.Windows.Forms.ToolBarButton
        Me.btnSaveTemplate = New System.Windows.Forms.ToolBarButton
        Me.btnSepies = New System.Windows.Forms.ToolBarButton
        Me.btnAddObjectiveType = New System.Windows.Forms.ToolBarButton
        Me.btnAddUnitType = New System.Windows.Forms.ToolBarButton
        Me.btnAddTokenType = New System.Windows.Forms.ToolBarButton
        Me.btnSep = New System.Windows.Forms.ToolBarButton
        Me.btnAddRule = New System.Windows.Forms.ToolBarButton
        Me.btnAddResource = New System.Windows.Forms.ToolBarButton
        Me.btnAddOrder = New System.Windows.Forms.ToolBarButton
        Me.btnSep2 = New System.Windows.Forms.ToolBarButton
        Me.btnElementManager = New System.Windows.Forms.ToolBarButton
        Me.btnEditFactions = New System.Windows.Forms.ToolBarButton
        Me.btnAddDeploymentZone = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
        Me.btnView = New System.Windows.Forms.ToolBarButton
        Me.btnFastEdit = New System.Windows.Forms.ToolBarButton
        Me.imlToolbarIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.pnlMap = New System.Windows.Forms.Panel
        Me.lblMap = New System.Windows.Forms.Label
        Me.btnOpenMap = New System.Windows.Forms.Button
        Me.chkDemo = New System.Windows.Forms.CheckBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtNewCampaign = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.txtMaxTurns = New System.Windows.Forms.TextBox
        Me.cboTurnLength = New System.Windows.Forms.ComboBox
        Me.btnDelete = New System.Windows.Forms.Button
        Me.btnProperties = New System.Windows.Forms.Button
        Me.tabOptions = New System.Windows.Forms.TabControl
        Me.tabMap = New System.Windows.Forms.TabPage
        Me.lblMapheight = New System.Windows.Forms.Label
        Me.lblMapWidth = New System.Windows.Forms.Label
        Me.tabGameOptions = New System.Windows.Forms.TabPage
        Me.numCombatRange = New System.Windows.Forms.NumericUpDown
        Me.lblCombatRange = New System.Windows.Forms.Label
        Me.chkHaltOnNewDetection = New System.Windows.Forms.CheckBox
        Me.lblMBGPV = New System.Windows.Forms.Label
        Me.numMaxBGPV = New System.Windows.Forms.NumericUpDown
        Me.chkOOBOnly = New System.Windows.Forms.CheckBox
        Me.chkUseZOC = New System.Windows.Forms.CheckBox
        Me.chkAllowReinforcements = New System.Windows.Forms.CheckBox
        Me.chkAllowPlayerManageChits = New System.Windows.Forms.CheckBox
        Me.tabDescription = New System.Windows.Forms.TabPage
        Me.txtCampaignDescription = New System.Windows.Forms.TextBox
        Me.imlTabPageImages = New System.Windows.Forms.ImageList(Me.components)
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.dspDefined = New Campaigner.ctlObjectDisplay
        Me.cmIndicatorOptions = New System.Windows.Forms.ContextMenuStrip(Me.components)
        Me.ValueIndicatorToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.NamedIndicatorToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.NamedValueIndicatorToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.tabOptions.SuspendLayout()
        Me.tabMap.SuspendLayout()
        Me.tabGameOptions.SuspendLayout()
        CType(Me.numCombatRange, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.numMaxBGPV, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.tabDescription.SuspendLayout()
        Me.cmIndicatorOptions.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(511, 545)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "OK"
        '
        'tlbAddItems
        '
        Me.tlbAddItems.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
        Me.tlbAddItems.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.btnOpenTemplate, Me.btnSaveTemplate, Me.btnSepies, Me.btnAddObjectiveType, Me.btnAddUnitType, Me.btnAddTokenType, Me.btnSep, Me.btnAddRule, Me.btnAddResource, Me.btnAddOrder, Me.btnSep2, Me.btnElementManager, Me.btnEditFactions, Me.btnAddDeploymentZone, Me.ToolBarButton1, Me.btnView, Me.btnFastEdit})
        Me.tlbAddItems.DropDownArrows = True
        Me.tlbAddItems.ImageList = Me.imlToolbarIcons
        Me.tlbAddItems.Location = New System.Drawing.Point(0, 0)
        Me.tlbAddItems.Name = "tlbAddItems"
        Me.tlbAddItems.ShowToolTips = True
        Me.tlbAddItems.Size = New System.Drawing.Size(599, 42)
        Me.tlbAddItems.TabIndex = 5
        '
        'btnOpenTemplate
        '
        Me.btnOpenTemplate.ImageIndex = 10
        Me.btnOpenTemplate.Name = "btnOpenTemplate"
        Me.btnOpenTemplate.Tag = "btnopentemplate"
        Me.btnOpenTemplate.Text = "Open"
        '
        'btnSaveTemplate
        '
        Me.btnSaveTemplate.ImageIndex = 11
        Me.btnSaveTemplate.Name = "btnSaveTemplate"
        Me.btnSaveTemplate.Tag = "btnsavetemplate"
        Me.btnSaveTemplate.Text = "Save"
        Me.btnSaveTemplate.ToolTipText = "Save as Template"
        '
        'btnSepies
        '
        Me.btnSepies.Name = "btnSepies"
        Me.btnSepies.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnAddObjectiveType
        '
        Me.btnAddObjectiveType.ImageIndex = 0
        Me.btnAddObjectiveType.Name = "btnAddObjectiveType"
        Me.btnAddObjectiveType.Tag = "btnaddobjectivetype"
        Me.btnAddObjectiveType.Text = "Installation"
        '
        'btnAddUnitType
        '
        Me.btnAddUnitType.ImageIndex = 1
        Me.btnAddUnitType.Name = "btnAddUnitType"
        Me.btnAddUnitType.Tag = "btnaddunittype"
        Me.btnAddUnitType.Text = "Unit"
        '
        'btnAddTokenType
        '
        Me.btnAddTokenType.ImageIndex = 2
        Me.btnAddTokenType.Name = "btnAddTokenType"
        Me.btnAddTokenType.Tag = "btnaddtokentype"
        Me.btnAddTokenType.Text = "Token"
        '
        'btnSep
        '
        Me.btnSep.Name = "btnSep"
        Me.btnSep.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnAddRule
        '
        Me.btnAddRule.ImageIndex = 3
        Me.btnAddRule.Name = "btnAddRule"
        Me.btnAddRule.Tag = "btnaddrule"
        Me.btnAddRule.Text = "Rule"
        '
        'btnAddResource
        '
        Me.btnAddResource.ImageIndex = 4
        Me.btnAddResource.Name = "btnAddResource"
        Me.btnAddResource.Tag = "btnaddresource"
        Me.btnAddResource.Text = "Resource"
        '
        'btnAddOrder
        '
        Me.btnAddOrder.ImageIndex = 5
        Me.btnAddOrder.Name = "btnAddOrder"
        Me.btnAddOrder.Tag = "btnaddindicator"
        Me.btnAddOrder.Text = "Indicator"
        Me.btnAddOrder.ToolTipText = "Add Indicator"
        '
        'btnSep2
        '
        Me.btnSep2.Name = "btnSep2"
        Me.btnSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnElementManager
        '
        Me.btnElementManager.ImageIndex = 7
        Me.btnElementManager.Name = "btnElementManager"
        Me.btnElementManager.Tag = "btnelementmanager"
        Me.btnElementManager.Text = "Elements"
        '
        'btnEditFactions
        '
        Me.btnEditFactions.ImageIndex = 6
        Me.btnEditFactions.Name = "btnEditFactions"
        Me.btnEditFactions.Tag = "btneditfactions"
        Me.btnEditFactions.Text = "Faction"
        '
        'btnAddDeploymentZone
        '
        Me.btnAddDeploymentZone.Name = "btnAddDeploymentZone"
        Me.btnAddDeploymentZone.Tag = "btnadddeploymentzone"
        Me.btnAddDeploymentZone.Text = "Add Dep"
        Me.btnAddDeploymentZone.ToolTipText = "Allows a player to place a user defined deployment zone freely"
        Me.btnAddDeploymentZone.Visible = False
        '
        'ToolBarButton1
        '
        Me.ToolBarButton1.Name = "ToolBarButton1"
        Me.ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnView
        '
        Me.btnView.ImageIndex = 8
        Me.btnView.Name = "btnView"
        Me.btnView.Tag = "btnView"
        Me.btnView.Text = "View"
        '
        'btnFastEdit
        '
        Me.btnFastEdit.ImageIndex = 9
        Me.btnFastEdit.Name = "btnFastEdit"
        Me.btnFastEdit.Tag = "btnfedit"
        Me.btnFastEdit.Text = "F. Edit"
        '
        'imlToolbarIcons
        '
        Me.imlToolbarIcons.ImageStream = CType(resources.GetObject("imlToolbarIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlToolbarIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlToolbarIcons.Images.SetKeyName(0, "")
        Me.imlToolbarIcons.Images.SetKeyName(1, "")
        Me.imlToolbarIcons.Images.SetKeyName(2, "")
        Me.imlToolbarIcons.Images.SetKeyName(3, "")
        Me.imlToolbarIcons.Images.SetKeyName(4, "")
        Me.imlToolbarIcons.Images.SetKeyName(5, "")
        Me.imlToolbarIcons.Images.SetKeyName(6, "")
        Me.imlToolbarIcons.Images.SetKeyName(7, "")
        Me.imlToolbarIcons.Images.SetKeyName(8, "iocSpreadsheet.ico")
        Me.imlToolbarIcons.Images.SetKeyName(9, "fedit.bmp")
        Me.imlToolbarIcons.Images.SetKeyName(10, "database_16.ico")
        Me.imlToolbarIcons.Images.SetKeyName(11, "importdata_16.ico")
        '
        'pnlMap
        '
        Me.pnlMap.BackColor = System.Drawing.Color.DimGray
        Me.pnlMap.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlMap.ForeColor = System.Drawing.SystemColors.InactiveCaption
        Me.pnlMap.Location = New System.Drawing.Point(8, 24)
        Me.pnlMap.Name = "pnlMap"
        Me.pnlMap.Size = New System.Drawing.Size(216, 161)
        Me.pnlMap.TabIndex = 6
        '
        'lblMap
        '
        Me.lblMap.AutoSize = True
        Me.lblMap.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMap.ForeColor = System.Drawing.Color.Black
        Me.lblMap.Location = New System.Drawing.Point(8, 196)
        Me.lblMap.Name = "lblMap"
        Me.lblMap.Size = New System.Drawing.Size(68, 13)
        Me.lblMap.TabIndex = 7
        Me.lblMap.Text = "Theater Map"
        '
        'btnOpenMap
        '
        Me.btnOpenMap.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOpenMap.Image = CType(resources.GetObject("btnOpenMap.Image"), System.Drawing.Image)
        Me.btnOpenMap.Location = New System.Drawing.Point(8, 0)
        Me.btnOpenMap.Name = "btnOpenMap"
        Me.btnOpenMap.Size = New System.Drawing.Size(32, 24)
        Me.btnOpenMap.TabIndex = 8
        '
        'chkDemo
        '
        Me.chkDemo.Checked = True
        Me.chkDemo.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkDemo.Enabled = False
        Me.chkDemo.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkDemo.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkDemo.Location = New System.Drawing.Point(8, 8)
        Me.chkDemo.Name = "chkDemo"
        Me.chkDemo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkDemo.Size = New System.Drawing.Size(160, 24)
        Me.chkDemo.TabIndex = 9
        Me.chkDemo.Text = "Demo Game"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Black
        Me.Label1.Location = New System.Drawing.Point(8, 73)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(66, 13)
        Me.Label1.TabIndex = 10
        Me.Label1.Text = "Game Name"
        '
        'txtNewCampaign
        '
        Me.txtNewCampaign.Location = New System.Drawing.Point(88, 69)
        Me.txtNewCampaign.Name = "txtNewCampaign"
        Me.txtNewCampaign.Size = New System.Drawing.Size(160, 20)
        Me.txtNewCampaign.TabIndex = 11
        Me.txtNewCampaign.Text = "New Campaign"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.Navy
        Me.Label2.Location = New System.Drawing.Point(8, 49)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(90, 13)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Basic Game Data"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.Color.Black
        Me.Label4.Location = New System.Drawing.Point(8, 108)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(65, 13)
        Me.Label4.TabIndex = 14
        Me.Label4.Text = "Turn Length"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.Color.Black
        Me.Label5.Location = New System.Drawing.Point(8, 139)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(57, 13)
        Me.Label5.TabIndex = 15
        Me.Label5.Text = "Max Turns"
        '
        'txtMaxTurns
        '
        Me.txtMaxTurns.Location = New System.Drawing.Point(88, 136)
        Me.txtMaxTurns.Name = "txtMaxTurns"
        Me.txtMaxTurns.Size = New System.Drawing.Size(160, 20)
        Me.txtMaxTurns.TabIndex = 16
        Me.txtMaxTurns.Text = "10"
        '
        'cboTurnLength
        '
        Me.cboTurnLength.Items.AddRange(New Object() {"Five Minutes", "Fifteen Minutes", "Half Hour", "One Hour", "Half Day", "One Day", "One Week", "One Month"})
        Me.cboTurnLength.Location = New System.Drawing.Point(88, 104)
        Me.cboTurnLength.Name = "cboTurnLength"
        Me.cboTurnLength.Size = New System.Drawing.Size(160, 21)
        Me.cboTurnLength.TabIndex = 17
        Me.cboTurnLength.Text = "One Hour"
        '
        'btnDelete
        '
        Me.btnDelete.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDelete.Image = CType(resources.GetObject("btnDelete.Image"), System.Drawing.Image)
        Me.btnDelete.Location = New System.Drawing.Point(559, 507)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(32, 23)
        Me.btnDelete.TabIndex = 18
        Me.btnDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'btnProperties
        '
        Me.btnProperties.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnProperties.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnProperties.Image = CType(resources.GetObject("btnProperties.Image"), System.Drawing.Image)
        Me.btnProperties.Location = New System.Drawing.Point(528, 507)
        Me.btnProperties.Name = "btnProperties"
        Me.btnProperties.Size = New System.Drawing.Size(32, 23)
        Me.btnProperties.TabIndex = 19
        Me.btnProperties.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'tabOptions
        '
        Me.tabOptions.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.tabOptions.Controls.Add(Me.tabMap)
        Me.tabOptions.Controls.Add(Me.tabGameOptions)
        Me.tabOptions.Controls.Add(Me.tabDescription)
        Me.tabOptions.Location = New System.Drawing.Point(8, 168)
        Me.tabOptions.Name = "tabOptions"
        Me.tabOptions.SelectedIndex = 0
        Me.tabOptions.Size = New System.Drawing.Size(248, 337)
        Me.tabOptions.TabIndex = 21
        '
        'tabMap
        '
        Me.tabMap.Controls.Add(Me.lblMapheight)
        Me.tabMap.Controls.Add(Me.lblMapWidth)
        Me.tabMap.Controls.Add(Me.pnlMap)
        Me.tabMap.Controls.Add(Me.btnOpenMap)
        Me.tabMap.Controls.Add(Me.lblMap)
        Me.tabMap.Location = New System.Drawing.Point(4, 22)
        Me.tabMap.Name = "tabMap"
        Me.tabMap.Size = New System.Drawing.Size(240, 311)
        Me.tabMap.TabIndex = 0
        Me.tabMap.Text = "Map"
        '
        'lblMapheight
        '
        Me.lblMapheight.Location = New System.Drawing.Point(16, 240)
        Me.lblMapheight.Name = "lblMapheight"
        Me.lblMapheight.Size = New System.Drawing.Size(192, 16)
        Me.lblMapheight.TabIndex = 10
        Me.lblMapheight.Text = "Height: "
        '
        'lblMapWidth
        '
        Me.lblMapWidth.Location = New System.Drawing.Point(16, 216)
        Me.lblMapWidth.Name = "lblMapWidth"
        Me.lblMapWidth.Size = New System.Drawing.Size(200, 16)
        Me.lblMapWidth.TabIndex = 9
        Me.lblMapWidth.Text = "Width: "
        '
        'tabGameOptions
        '
        Me.tabGameOptions.Controls.Add(Me.numCombatRange)
        Me.tabGameOptions.Controls.Add(Me.lblCombatRange)
        Me.tabGameOptions.Controls.Add(Me.chkHaltOnNewDetection)
        Me.tabGameOptions.Controls.Add(Me.lblMBGPV)
        Me.tabGameOptions.Controls.Add(Me.numMaxBGPV)
        Me.tabGameOptions.Controls.Add(Me.chkOOBOnly)
        Me.tabGameOptions.Controls.Add(Me.chkUseZOC)
        Me.tabGameOptions.Controls.Add(Me.chkAllowReinforcements)
        Me.tabGameOptions.Controls.Add(Me.chkAllowPlayerManageChits)
        Me.tabGameOptions.Controls.Add(Me.chkDemo)
        Me.tabGameOptions.Location = New System.Drawing.Point(4, 22)
        Me.tabGameOptions.Name = "tabGameOptions"
        Me.tabGameOptions.Size = New System.Drawing.Size(240, 311)
        Me.tabGameOptions.TabIndex = 1
        Me.tabGameOptions.Text = "Options"
        '
        'numCombatRange
        '
        Me.numCombatRange.Location = New System.Drawing.Point(26, 262)
        Me.numCombatRange.Maximum = New Decimal(New Integer() {64, 0, 0, 0})
        Me.numCombatRange.Minimum = New Decimal(New Integer() {8, 0, 0, 0})
        Me.numCombatRange.Name = "numCombatRange"
        Me.numCombatRange.Size = New System.Drawing.Size(120, 20)
        Me.numCombatRange.TabIndex = 31
        Me.numCombatRange.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numCombatRange.Value = New Decimal(New Integer() {8, 0, 0, 0})
        '
        'lblCombatRange
        '
        Me.lblCombatRange.AutoSize = True
        Me.lblCombatRange.Location = New System.Drawing.Point(5, 246)
        Me.lblCombatRange.Name = "lblCombatRange"
        Me.lblCombatRange.Size = New System.Drawing.Size(78, 13)
        Me.lblCombatRange.TabIndex = 30
        Me.lblCombatRange.Text = "Combat Range"
        '
        'chkHaltOnNewDetection
        '
        Me.chkHaltOnNewDetection.Checked = True
        Me.chkHaltOnNewDetection.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkHaltOnNewDetection.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkHaltOnNewDetection.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkHaltOnNewDetection.Location = New System.Drawing.Point(8, 164)
        Me.chkHaltOnNewDetection.Name = "chkHaltOnNewDetection"
        Me.chkHaltOnNewDetection.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkHaltOnNewDetection.Size = New System.Drawing.Size(184, 24)
        Me.chkHaltOnNewDetection.TabIndex = 29
        Me.chkHaltOnNewDetection.Text = "Halt on New Detection"
        '
        'lblMBGPV
        '
        Me.lblMBGPV.AutoSize = True
        Me.lblMBGPV.Location = New System.Drawing.Point(5, 203)
        Me.lblMBGPV.Name = "lblMBGPV"
        Me.lblMBGPV.Size = New System.Drawing.Size(102, 13)
        Me.lblMBGPV.TabIndex = 28
        Me.lblMBGPV.Text = "Max BG Point Value"
        '
        'numMaxBGPV
        '
        Me.numMaxBGPV.Location = New System.Drawing.Point(26, 220)
        Me.numMaxBGPV.Maximum = New Decimal(New Integer() {32000, 0, 0, 0})
        Me.numMaxBGPV.Name = "numMaxBGPV"
        Me.numMaxBGPV.Size = New System.Drawing.Size(120, 20)
        Me.numMaxBGPV.TabIndex = 27
        Me.numMaxBGPV.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'chkOOBOnly
        '
        Me.chkOOBOnly.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkOOBOnly.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkOOBOnly.Location = New System.Drawing.Point(8, 38)
        Me.chkOOBOnly.Name = "chkOOBOnly"
        Me.chkOOBOnly.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkOOBOnly.Size = New System.Drawing.Size(160, 24)
        Me.chkOOBOnly.TabIndex = 26
        Me.chkOOBOnly.Text = "Allow Only Order Of Battle"
        '
        'chkUseZOC
        '
        Me.chkUseZOC.Checked = True
        Me.chkUseZOC.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkUseZOC.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkUseZOC.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkUseZOC.Location = New System.Drawing.Point(8, 130)
        Me.chkUseZOC.Name = "chkUseZOC"
        Me.chkUseZOC.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkUseZOC.Size = New System.Drawing.Size(184, 24)
        Me.chkUseZOC.TabIndex = 25
        Me.chkUseZOC.Text = "Use Zones Of Control"
        '
        'chkAllowReinforcements
        '
        Me.chkAllowReinforcements.Checked = True
        Me.chkAllowReinforcements.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkAllowReinforcements.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkAllowReinforcements.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkAllowReinforcements.Location = New System.Drawing.Point(8, 100)
        Me.chkAllowReinforcements.Name = "chkAllowReinforcements"
        Me.chkAllowReinforcements.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkAllowReinforcements.Size = New System.Drawing.Size(184, 24)
        Me.chkAllowReinforcements.TabIndex = 23
        Me.chkAllowReinforcements.Text = "Allow Reinforcements"
        '
        'chkAllowPlayerManageChits
        '
        Me.chkAllowPlayerManageChits.Checked = True
        Me.chkAllowPlayerManageChits.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkAllowPlayerManageChits.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkAllowPlayerManageChits.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkAllowPlayerManageChits.Location = New System.Drawing.Point(8, 68)
        Me.chkAllowPlayerManageChits.Name = "chkAllowPlayerManageChits"
        Me.chkAllowPlayerManageChits.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkAllowPlayerManageChits.Size = New System.Drawing.Size(184, 24)
        Me.chkAllowPlayerManageChits.TabIndex = 21
        Me.chkAllowPlayerManageChits.Text = "Allow Players To Manage Chits"
        '
        'tabDescription
        '
        Me.tabDescription.Controls.Add(Me.txtCampaignDescription)
        Me.tabDescription.Location = New System.Drawing.Point(4, 22)
        Me.tabDescription.Name = "tabDescription"
        Me.tabDescription.Size = New System.Drawing.Size(240, 311)
        Me.tabDescription.TabIndex = 2
        Me.tabDescription.Text = "Description"
        '
        'txtCampaignDescription
        '
        Me.txtCampaignDescription.Location = New System.Drawing.Point(8, 8)
        Me.txtCampaignDescription.Multiline = True
        Me.txtCampaignDescription.Name = "txtCampaignDescription"
        Me.txtCampaignDescription.Size = New System.Drawing.Size(224, 280)
        Me.txtCampaignDescription.TabIndex = 0
        Me.txtCampaignDescription.Text = "Enter Campaign Description"
        '
        'imlTabPageImages
        '
        Me.imlTabPageImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        Me.imlTabPageImages.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlTabPageImages.TransparentColor = System.Drawing.Color.Transparent
        '
        'Panel1
        '
        Me.Panel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel1.BackColor = System.Drawing.SystemColors.ControlDark
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Location = New System.Drawing.Point(8, 533)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(583, 8)
        Me.Panel1.TabIndex = 22
        '
        'dspDefined
        '
        Me.dspDefined.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.dspDefined.Location = New System.Drawing.Point(264, 48)
        Me.dspDefined.Name = "dspDefined"
        Me.dspDefined.ShowLowerGrid = True
        Me.dspDefined.Size = New System.Drawing.Size(335, 457)
        Me.dspDefined.TabIndex = 4
        '
        'cmIndicatorOptions
        '
        Me.cmIndicatorOptions.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ValueIndicatorToolStripMenuItem, Me.NamedIndicatorToolStripMenuItem, Me.NamedValueIndicatorToolStripMenuItem})
        Me.cmIndicatorOptions.Name = "cmIndicatorOptions"
        Me.cmIndicatorOptions.Size = New System.Drawing.Size(194, 70)
        '
        'ValueIndicatorToolStripMenuItem
        '
        Me.ValueIndicatorToolStripMenuItem.Name = "ValueIndicatorToolStripMenuItem"
        Me.ValueIndicatorToolStripMenuItem.Size = New System.Drawing.Size(193, 22)
        Me.ValueIndicatorToolStripMenuItem.Text = "Value Indicator"
        '
        'NamedIndicatorToolStripMenuItem
        '
        Me.NamedIndicatorToolStripMenuItem.Name = "NamedIndicatorToolStripMenuItem"
        Me.NamedIndicatorToolStripMenuItem.Size = New System.Drawing.Size(193, 22)
        Me.NamedIndicatorToolStripMenuItem.Text = "Named Indicator"
        '
        'NamedValueIndicatorToolStripMenuItem
        '
        Me.NamedValueIndicatorToolStripMenuItem.Name = "NamedValueIndicatorToolStripMenuItem"
        Me.NamedValueIndicatorToolStripMenuItem.Size = New System.Drawing.Size(193, 22)
        Me.NamedValueIndicatorToolStripMenuItem.Text = "Named Value Indicator"
        '
        'frmNewEmptyCampaign
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(599, 575)
        Me.ControlBox = False
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.tabOptions)
        Me.Controls.Add(Me.btnProperties)
        Me.Controls.Add(Me.btnDelete)
        Me.Controls.Add(Me.cboTurnLength)
        Me.Controls.Add(Me.txtMaxTurns)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtNewCampaign)
        Me.Controls.Add(Me.tlbAddItems)
        Me.Controls.Add(Me.dspDefined)
        Me.Controls.Add(Me.btnOK)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmNewEmptyCampaign"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Main Editor"
        Me.tabOptions.ResumeLayout(False)
        Me.tabMap.ResumeLayout(False)
        Me.tabMap.PerformLayout()
        Me.tabGameOptions.ResumeLayout(False)
        Me.tabGameOptions.PerformLayout()
        CType(Me.numCombatRange, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.numMaxBGPV, System.ComponentModel.ISupportInitialize).EndInit()
        Me.tabDescription.ResumeLayout(False)
        Me.tabDescription.PerformLayout()
        Me.cmIndicatorOptions.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub OpenFMP(ByVal filePath As String)
        ' set the map, and try to load a small "thumbnail of it"
        Try
            ' strip down to the actual filepath

            ptrCGD.TheaterMapFilename = FMPNameFromFile(filePath)

            _fmpDisp = New FMPLib01.FlexMapData()
            _fmpDisp = _fmpDisp.OpenMap(filePath)

            Dim im As Image = New Bitmap(_fmpDisp.Width, _fmpDisp.Height)
            Dim g As Graphics = Graphics.FromImage(im)

            _fmpDisp.Render(g, g.VisibleClipBounds, False)

            ' draw the overview map
            Dim bmp As Bitmap = im

            Dim deleg As Bitmap.GetThumbnailImageAbort

            pnlMap.BackgroundImage = bmp.GetThumbnailImage(pnlMap.Width, pnlMap.Height, deleg, IntPtr.Zero)

            mClassTypes = _fmpDisp.MoveTypeLookup

            g.Dispose()

            GC.Collect()
            Dim milesWide As Integer
            Dim milesHeight As Integer

            milesWide = (_fmpDisp.Width / _fmpDisp.MapScale.PixelCount) * _fmpDisp.MapScale.MilesPerPixelCount
            milesHeight = (_fmpDisp.Height / _fmpDisp.MapScale.PixelCount) * _fmpDisp.MapScale.MilesPerPixelCount

            lblMapWidth.Text = "Width: " & milesWide & " " & _fmpDisp.unitName
            lblMapheight.Text = "Height: " & milesHeight & " " & _fmpDisp.unitName

        Catch ex As Exception
            ' if there's an error, we want the name going back to "none"
            ptrCGD.TheaterMapFilename = "none"
            MsgBox("Could not open to render into map. Please check the mapfile, error '" & ex.Message & "'", MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Function FMPNameFromFile(ByVal filepath As String) As String
        'returns the filename.
        Dim c As Char
        Dim lastSlash As Integer
        Dim i As Integer = -1
        Dim stripped As String

        For Each c In filepath
            i += 1
            If c = "\" Then
                If i > lastSlash Then lastSlash = i
            End If
        Next

        stripped -= 1
        stripped = filepath.Substring(lastSlash)
        Return stripped
    End Function

    Private Sub btnOpenMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenMap.Click
        Dim fileopen As New OpenFileDialog()

        fileopen.Filter = "FlexMaps *.fmp | *.fmp"

        fileopen.ShowDialog()

        Dim filepath As String = fileopen.FileName
        OpenFMP(filepath)

    End Sub

    Private Function VerifyAll() As Boolean
        ' ensures all required information is included, such as a map filepath and icons, etc. Will display a little report saying what may be missing.
        ' returns false if not all requirements are met.

    End Function

    Private Sub tlbAddItems_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tlbAddItems.ButtonClick
        Select Case e.Button.Tag.ToString.ToLower
            Case Is = "btnsavetemplate" : SaveTemplate()
            Case Is = "btnopentemplate" : LoadTemplate()
            Case Is = "btnaddobjectivetype" : AddObjectiveType()
            Case Is = "btnaddunittype" : AddUnitType()
            Case Is = "btnaddtokentype" : AddTokenType()
            Case Is = "btnaddrule" : AddRule()
            Case Is = "btnaddresource" : AddResource()
            Case Is = "btnaddorder" : AddOrder()
            Case Is = "btnaddindicator" : AddIndicator()
            Case Is = "btneditfactions" : EditFactions()
            Case Is = "btnelementmanager" : EditElements()
            Case Is = "btnadddeploymentzone" : AddDeploymentZone()
            Case Is = "btnaddindicator" : AddIndicator()
            Case Is = "btnview"
                '// this will open the spreadsheet view
                If _fmpDisp Is Nothing Then
                    MessageBox.Show("You must select a map before choosing this option.", "Select Map", MessageBoxButtons.OK)
                    Exit Sub
                End If
                Dim fSpread As New frmChitSpreadsheet
                fSpread.ShowDialog(ptrCGD, _fmpDisp.MoveTypeLookup)
                Exit Sub
            Case Is = "btnfedit"
                Dim fe As New frmFastEditor(ptrCGD)
                fe.ShowDialog()
                Exit Sub
        End Select

        ' refresh the list
        dspDefined.ListItems()

    End Sub

    Private Sub SaveTemplate()
        Try
            '// create a new template with all of the guys
            Dim savetemp As New CampaignerTemplate
            savetemp.installations = ptrCGD.ObjectiveTypes
            savetemp.Resources = ptrCGD.ResourceTypes_g
            savetemp.rules = ptrCGD.RuleTypes_g
            savetemp.Units = ptrCGD.UnitTypes
            savetemp.elements = ptrCGD.ElementMan  '// 1.0.2.0 don't forget elements! cuz... you did!

            Dim sav As New SaveFileDialog
            sav.Filter = "Campaigner Template | *.ctemplate"
            sav.ShowDialog()

            Try
                If sav.FileName = "" Then Exit Sub
                savetemp.Save(sav.FileName)
            Catch ex As Exception
                MessageBox.Show(ex.Message, "no")
            End Try

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub LoadTemplate()
        Try
            Dim loadtemp As New CampaignerTemplate
            Dim loa As New OpenFileDialog
            Dim col As New Collection

            loa.Filter = "Campaigner Template | *.ctemplate"
            loa.ShowDialog()

            If loa.FileName = "" Then Exit Sub
            loadtemp = loadtemp.Load(loa.FileName)

            Dim skey As String

            '// resources
            For Each skey In loadtemp.Resources.HT.Keys

                If (skey <> "Deployment Point") AndAlso (skey <> "REST1") Then
                    Dim rest As ResourceType = ptrCGD.ResourceTypes_g.Item(skey)

                    If rest Is Nothing Then '// if the item name does not already exist... yikes, if it does, we begin to have probs
                        ptrCGD.ResourceTypes_g.Add(loadtemp.Resources.Item(skey), loadtemp.Resources.Item(skey).ResourceName)
                    End If

                End If
            Next

            For Each skey In loadtemp.rules.HT.Keys
                Dim ru As RuleType = ptrCGD.RuleTypes_g.Item(skey)

                If ru Is Nothing Then
                    ptrCGD.RuleTypes_g.Add(loadtemp.rules.Item(skey), loadtemp.rules.Item(skey).RuleName)
                    'Else
                    '    MessageBox.Show("Some of the items being loaded have the same name as existing items. Not all items will be able to be imported.", "Aborting Import", MessageBoxButtons.OK)
                    '    dspDefined.ListItems()
                    '    Exit Sub
                End If
            Next

            For Each un As UnitType In loadtemp.Units
                ptrCGD.UnitTypes.add(un)
            Next

            For Each inst As ObjectiveType In loadtemp.installations
                ptrCGD.ObjectiveTypes.add(inst)
            Next

            '// elementos! The freshmaker! added 1.0.2.0, so some older templates might not have them
            If Not loadtemp.elements Is Nothing Then
                For Each eclass As ElementClass In loadtemp.elements.DefinedElementClasses
                    ptrCGD.ElementMan.DefinedElementClasses.Add(eclass)
                Next

                For Each etype As ElementType In loadtemp.elements.DefinedElementTypes
                    ptrCGD.ElementMan.DefinedElementTypes.Add(etype)
                Next

            End If

            dspDefined.ListItems()

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            SaveGameProperties()
        Catch ex As Exception
            HandleException(c_Module, ex)
            Exit Sub
        End Try

        mCancelPressed = False
        Me.Dispose()
    End Sub

    Private Sub SaveGameProperties()
        Try
            ptrCGD.GameName = txtNewCampaign.Text
            ptrCGD.MaxTurns = CInt(txtMaxTurns.Text)
            ptrCGD.AllowPlayerManageChits = chkAllowPlayerManageChits.Checked
            ptrCGD.ForceOOB = chkOOBOnly.Checked
            ptrCGD.AllowReinforcements = chkAllowReinforcements.Checked
            ptrCGD.CampaignDescription = txtCampaignDescription.Text
            ptrCGD.BattlegroupMaxPointValue = numMaxBGPV.Value
            ptrCGD.UsesZOC = chkUseZOC.Checked
            ptrCGD.haltOnNewDetection = chkHaltOnNewDetection.Checked
            ptrCGD.combatEngagementRange = numCombatRange.Value

            updateTurnLength()

            Dim obj As Object
            Dim datamap(255) As Byte
            obj = ptrCGD.SystemValue("datamap")
            If TypeOf obj Is String Then
                ptrCGD.SetUpDataMapping()
                datamap = ptrCGD.SystemValue("datamap")
            Else
                datamap = ptrCGD.SystemValue("datamap")
            End If

#If MASTER = 1 Then
            ptrCGD.SetUpDataMapping()
            If chkDemo.Checked Then
                datamap(221) = 32
            Else
                datamap(221) = 0
            End If
            ptrCGD.SystemValue("datamap") = datamap
#Else
            datamap(221) = 0 '// definately not demo
            'ptrcgd.Demo =False
            ptrCGD.SystemValue("datamap") = datamap
#End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub updateTurnLength()
        Try
            Select Case cboTurnLength.Text
                Case Is = "Five Minutes" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FiveMinute
                Case Is = "Fifteen Minutes" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FifteenMinute
                Case Is = "Half Hour" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.HalfHour
                Case Is = "One Hour" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Hour
                Case Is = "Half Day" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.HalfDay
                Case Is = "One Day" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FullDay
                Case Is = "One Week" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Week
                Case Is = "One Month" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Month
            End Select
        Catch ex As Exception
            '// no change
        End Try

    End Sub

#Region "Add Objects"

    Private Sub AddObjectiveType()
        Try
            If ptrCGD.TheaterMapFilename = "none" Then
                MsgBox("You must select a theater map before adding ground chits.", MsgBoxStyle.Information, "Add Theater Map")
                Exit Sub
            End If

            Dim newItem As New cmplib01.ObjectiveType()
            Dim path As String
            Dim basePath As String = System.Reflection.Assembly.GetExecutingAssembly.Location()

            basePath = basePath.Replace("Campaigner.exe", "icons\")

            ' System.Reflection.Assembly.GetExecutingAssembly.Location()  <-- replaces app.path
            Try
                ' set up the new icons for this guy...
                path = basePath + "basicobjective.bmp"
                newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Bitmap.FromFile(path)

                path = basePath + "basicobjectiveenemy.bmp"
                newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Bitmap.FromFile(path)

                path = basePath + "basicobjectivesamefaction.bmp"
                newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Bitmap.FromFile(path)

            Catch ex As Exception
                newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Nothing
                newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Nothing
                newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Nothing
            End Try

            ' set the name of the new succa
            newItem.Description = "New Installation Type"
            newItem.TypeName = "New Installation Type"
            newItem.Name = "New Installation Type"
            newItem.GroundChitClass = cmplib01.GroundChitClass_cgd.Objective

            Dim frmAddChit As New frmChitProperties(frmChitProperties.OpenMode.ObjectiveType, ptrCGD, newItem, mClassTypes, False)

            frmAddChit.ShowDialog()

            '// exit if cancelled
            If frmAddChit.actionCancelled Then Exit Sub

            ' add the edited chit to the collection
            Dim done As Boolean
            Do Until done = True
                Try
                    ptrCGD.ObjectiveTypes.add(newItem)
                    done = True
                Catch ex As Exception
                    newItem.Name = InputBox("You must enter a unique name.", "Invalid Name")
                    done = False
                End Try
            Loop
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub AddUnitType()
        If ptrCGD.TheaterMapFilename = "none" Then
            MsgBox("You must select a theater map before adding ground chits.", MsgBoxStyle.Information, "Add Theater Map")
            Exit Sub
        End If

        Dim newItem As New cmplib01.UnitType
        Dim path As String
        Dim basePath As String = System.Reflection.Assembly.GetExecutingAssembly.Location()
        Dim baseType As String

        basePath = basePath.Replace("Campaigner.exe", "icons\")

        ' System.Reflection.Assembly.GetExecutingAssembly.Location()  <-- replaces app.path
        Try
            ' set up the new icons for this guy...
            path = basePath + "basicunit.bmp"
            newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Bitmap.FromFile(path)

            path = basePath + "basicunitenemy.bmp"
            newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Bitmap.FromFile(path)

            path = basePath + "basicunitsamefaction.bmp"
            newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Bitmap.FromFile(path)

        Catch ex As Exception
            newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Nothing
            newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Nothing
            newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Nothing
            Debug.WriteLine("!!! Error in opening file for icons: " & ex.Message.ToString)
        End Try

        newItem.Description = "New Unit Type"
        newItem.TypeName = "New Unit Type"
        newItem.Name = "New Unit Type"
        newItem.GroundChitClass = cmplib01.GroundChitClass_cgd.Unit

        Dim frmAddChit As New frmChitProperties(frmChitProperties.OpenMode.UnitType, ptrCGD, newItem, mClassTypes, False)

        frmAddChit.ShowDialog()

        If frmAddChit.actionCancelled Then Exit Sub

        ' add edited unit to collection
        Dim bDone As Boolean

        Do Until bDone
            Try
                ptrCGD.UnitTypes.add(newItem)
                bDone = True
            Catch ex As Exception
                '// try adding something with a different name.
                'MessageBox.Show("Unit Types must have unique names, please enter a different name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Hand)
                newItem.TypeName = InputBox("Unit types must have unique names, please enter a different name.", "Invalid Name")
                'newItem.BoostMCID()
                'HACK
                'newItem.TypeID = newItem.ID
                bDone = False
            End Try
        Loop

    End Sub

    Private Sub AddTokenType()

        Try
            If ptrCGD.TheaterMapFilename = "none" Then
                MsgBox("You must select a theater map before adding ground chits.", MsgBoxStyle.Information, "Add Theater Map")
                Exit Sub
            End If

            Dim f As New frmTokenType
            f.ShowDialog(ptrCGD, _fmpDisp)

            If f.Cancelled Then Exit Sub

            '// duplicate names have already been checked
            ptrCGD.TokenTypes.Add(f.Token.tokenTypeName, f.Token)



        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try


        'If ptrCGD.RuleTypes_g.Count = 0 Then
        '    MsgBox("There must be at least one rule defined before you may create token types.", MsgBoxStyle.Information, "Define Rules")
        '    Exit Sub
        'End If

        'Dim newItem As New cmplib01.TokenType
        'Dim path As String
        'Dim basePath As String = System.Reflection.Assembly.GetExecutingAssembly.Location()
        'Dim baseType As String

        'basePath = basePath.Replace("Campaigner.exe", "icons\")

        'Try
        '    ' set up default icons
        '    path = basePath + "basictoken.bmp"
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Bitmap.FromFile(path)
        '    path = basePath + "basictokenenemy.bmp"
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Bitmap.FromFile(path)
        '    path = basePath + "basictokensamefaction.bmp"
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Bitmap.FromFile(path)
        'Catch ex As Exception
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.Owner) = Nothing
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.Enemy) = Nothing
        '    newItem.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = Nothing
        '    Debug.WriteLine("!!! Error in opening file for icons: " & ex.Message.ToString)
        'End Try
        'newItem.MovementClassID = 2
        'newItem.Description = "New Token Type"
        'newItem.TypeName = "New Token Type"
        'newItem.Name = "New Token Type"
        'newItem.GroundChitClass = cmplib01.GroundChitClass_cgd.Token
        '' when adding a new token, we assign the first one found in the rules to the token, okay, so its an ugly hack.
        'Dim de As DictionaryEntry
        'Dim sKey As String

        'For Each de In ptrCGD.RuleTypes_g.HT
        '    sKey = de.Key.ToString
        '    newItem.TokenRule.ruleTypeID = ptrCGD.RuleTypes_g.Item(sKey).RuleTypeID
        '    newItem.TokenRule.ruleName = ptrCGD.RuleTypes_g.Item(sKey).RuleName
        '    newItem.TokenRule.currentUses = ptrCGD.RuleTypes_g.Item(sKey).MaxUses
        '    Exit For
        'Next

        'Dim frmAddChit As New frmChitProperties(frmChitProperties.OpenMode.TokenType, ptrCGD, newItem, mClassTypes)
        'frmAddChit.ShowDialog()

        'ptrCGD.TokenTypes.Add(newItem.Key, newItem)

    End Sub

    Private Sub AddRule()
        Dim newRuleType As New cmplib01.ResourceConsumingRuleType
        Dim fNewRule As New frmRulePicker(ptrCGD, newRuleType, "unit")
        Dim bAdded As Boolean = False

        fNewRule.ShowDialog()

        If Not fNewRule.CancelPressed Then

            Do Until bAdded
                Try
                    ptrCGD.RuleTypes_g.Add(newRuleType, newRuleType.RuleName)
                    bAdded = True
                Catch ex As Exception
                    newRuleType.RuleName = InputBox("Rule Type names must have unique names, please enter a different name.", "Invalid Name")
                    bAdded = False
                End Try
            Loop

        End If

    End Sub

    Private Sub AddResource()
        Try
            Dim newResourceType As New cmplib01.ResourceType
            Dim fNewResource As New frmAddNewResourceType(newResourceType)
            Dim done As Boolean

            fNewResource.ShowDialog()
            If Not fNewResource.CancelPressed Then
                Do Until done
                    Try
                        ptrCGD.ResourceTypes_g.Add(newResourceType, newResourceType.ResourceName)
                        done = True
                    Catch ex As Exception
                        newResourceType.ResourceName = InputBox("Resource Type names must be unique, please enter a different name.", "Invalid Name")
                        done = False
                    End Try
                Loop
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub AddOrder()
        'Dim newOrder As New cmplib01.OrderType
        'Dim fNewOrder As New frmOrderType(newOrder)

        'fNewOrder.ShowDialog()
        'If Not fNewOrder.CancelPressed Then
        '    ' add the new order to the campaign game
        '    ptrCGD.Orders_g.Add(newOrder, newOrder.Key)
        'End If


    End Sub

    Private Sub AddIndicator()
        Try
            Dim f As New frmIndicatorProperties
            f.ShowDialogNewIndicator()

            If f.Cancelled = False Then
                If ptrCGD.Indicators.ContainsKey(f.Indi.IndicatorName) Then
                    MessageBox.Show("There is an indicator with that name already.", "Duplicate Name", MessageBoxButtons.OK, MessageBoxIcon.Hand)
                    Exit Sub
                End If
                ptrCGD.Indicators.Add(f.Indi.IndicatorName, f.Indi)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub EditElements()
        Dim fMan As New frmElementManager(ptrCGD)

        fMan.ShowDialog()

    End Sub

    Private Sub EditFactions()
        Dim fFact As New frmEditFactions(ptrCGD.Faction_g)

        fFact.ShowDialog()

    End Sub
#End Region

#Region "Edit Objects"
    Private Sub EditObjectiveType(ByRef objt As cmplib01.GroundChitType)
        Dim fChit As New frmChitProperties(frmChitProperties.OpenMode.ObjectiveType, ptrCGD, objt, mClassTypes, "units", True)

        fChit.ShowDialog()

    End Sub

    Private Sub EditUnitType(ByRef objt As GroundChitType)
        Dim fChit As New frmChitProperties(frmChitProperties.OpenMode.UnitType, ptrCGD, objt, mClassTypes, "units", True)

        fChit.ShowDialog()
    End Sub

    Private Sub EditTokenType(ByVal sKey As String)
        Dim objT As cmplib01.GroundChitType = ptrCGD.TokenTypes(sKey)
        Dim fChit As New frmChitProperties(frmChitProperties.OpenMode.TokenType, ptrCGD, objT, mClassTypes, True)

        fChit.ShowDialog()
    End Sub

    Private Sub EditRuleType(ByVal sKey As String)
        Dim fRul As New frmRulePicker(ptrCGD, ptrCGD.RuleTypes_g.Item(sKey), True)

        fRul.ShowDialog()

    End Sub

    Private Sub EditResourceType(ByVal sKey As String)
        Dim resT As cmplib01.ResourceType = ptrCGD.ResourceTypes_g.Item(sKey)
        Dim fRes As New frmAddNewResourceType(resT)

        fRes.ShowDialog()

    End Sub

    Private Sub EditOrderType(ByVal sKey As String)
        Dim ordT As cmplib01.OrderType = ptrCGD.Orders_g.Item(sKey)
        Dim fOrd As New frmOrderType(ordT)

        fOrd.ShowDialog()

    End Sub

#End Region


    Private Sub ShowSelectedItemProperties()

        Try
            Select Case dspDefined.DisplayedObject.CampaignerObjectType
                Case cmplib01.CampaignerObjectType_cot.noItem : Exit Sub  '// nothing is selected
                Case cmplib01.CampaignerObjectType_cot.objective : EditObjectiveType(DirectCast(dspDefined.DisplayedObject.obj, cmplib01.ObjectiveType))
                Case cmplib01.CampaignerObjectType_cot.unit : EditUnitType(DirectCast(dspDefined.DisplayedObject.obj, UnitType))
                Case cmplib01.CampaignerObjectType_cot.rule : EditRuleType(DirectCast(dspDefined.DisplayedObject.obj, RuleType).RuleName)
                Case cmplib01.CampaignerObjectType_cot.resource : EditResourceType(DirectCast(dspDefined.DisplayedObject.obj, ResourceType).ResourceName)
                Case CampaignerObjectType_cot.token
                    Dim f As New frmTokenType
                    f.ShowDialog(DirectCast(dspDefined.DisplayedObject.obj, TokenType), ptrCGD, _fmpDisp)
                Case CampaignerObjectType_cot.indicator
                    Dim f As New frmIndicatorProperties
                    f.ShowDialog(DirectCast(dspDefined.DisplayedObject.obj, IIindciator))
            End Select

            '// this is supposed to refresh the items.
            dspDefined.ListItems()
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub AddDeploymentZone()

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        mCancelPressed = True
    End Sub


    Private Sub dspDefined_ItemSelected(ByRef obj As Object, ByRef objectType As cmplib01.CampaignerObjectType_cot) Handles dspDefined.ItemSelected

    End Sub

    Private Sub btnProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProperties.Click
        ShowSelectedItemProperties()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        DeleteSelectedItem(dspDefined.DisplayedObject)
    End Sub

    Private Sub DeleteSelectedItem(ByRef citem As CampaignerListViewItem)
        Dim res As MsgBoxResult
        res = MsgBox("Are you sure you wish to delete the selected item?", MsgBoxStyle.YesNo, "Delete Selected?")
        If res = MsgBoxResult.Yes Then
            Try

                If Not IsValidToDeleteObject(citem) Then
                    MessageBox.Show("There are other objects that rely on the one you are trying to delete. ", "Cannot Delete")
                    Exit Sub
                End If

                Select Case citem.CampaignerObjectType
                    Case CampaignerObjectType_cot.noItem : Exit Sub
                    Case CampaignerObjectType_cot.objective : ptrCGD.ObjectiveTypes.remove(citem.obj)
                    Case CampaignerObjectType_cot.unit : ptrCGD.UnitTypes.remove(citem.obj)
                    Case CampaignerObjectType_cot.rule : ptrCGD.RuleTypes_g.HT.Remove(citem.Text)
                    Case CampaignerObjectType_cot.resource : ptrCGD.Resources_g.HT.Remove(citem.Text)
                End Select
            Catch ex As Exception
                '// nothing deleted dude.
                HandleException(c_Module, ex)
            End Try
            dspDefined.ListItems()

        End If
    End Sub

    Private Function IsValidToDeleteObject(ByRef citem As CampaignerListViewItem) As Boolean
        '// we have to check:
        ' 1) if the item is a resource and being consumed by a rule, or generated by an installation
        ' 2) a rule being used by an installation type or unit type
        ' 3) an installation being used in a victory condition
        Try
            Select Case citem.CampaignerObjectType
                Case CampaignerObjectType_cot.resource
                    Return IsResourceValidToDelete(DirectCast(citem.obj, ResourceType))
                Case CampaignerObjectType_cot.rule
                    Return IsRuleValidToDelete(DirectCast(citem.obj, RuleType))
                Case CampaignerObjectType_cot.objective
                    Return IsInstallationValidToDelete(DirectCast(citem.obj, ObjectiveType))
                Case CampaignerObjectType_cot.unit
                    Return True
            End Select
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Function

    Private Function IsRuleValidToDelete(ByRef ru As RuleType) As Boolean
        Try
            '// installation types
            For Each obj As ObjectiveType In Me.ptrCGD.ObjectiveTypes
                For Each rut As RuleType In obj.GCRules
                    If rut.Equals(ru) Then Return False
                Next
            Next

            '// unit types
            For Each un As UnitType In Me.ptrCGD.UnitTypes
                For Each rut As RuleType In un.GCRules
                    If rut.Equals(ru) Then Return False
                Next
            Next

            Return True

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Function

    Private Function IsResourceValidToDelete(ByRef res As ResourceType) As Boolean
        Try
            Dim key As String

            '// installation types
            For Each obj As ObjectiveType In ptrCGD.ObjectiveTypes
                For Each key In obj.ObjectiveResources.HT.Keys
                    Dim re As Resource = obj.ObjectiveResources.Item(key)
                    If re.Equals(res) Then Return False
                Next
            Next

            '// rule types
            For Each ru As RuleType In ptrCGD.Rules_g
                If TypeOf ru Is ResourceConsumingRuleType Then
                    For Each resCo As ResourceCost In DirectCast(ru, ResourceConsumingRuleType).Costs
                        If resCo.ResourceTypeName = res.ResourceName Then Return False
                    Next
                End If
            Next

            '// and victory conditions
            'for each vc as IVictoryCondition in ptrcgd.fa
            For Each key In ptrCGD.Faction_g.HT.Keys
                Dim fact As Faction = ptrCGD.Faction_g.Item(key)
                For Each vc As IVictoryCondition In fact.FactionVictoryConditions
                    If vc.VCType = VictoryConditionClass_cgd.Resource Then
                        Dim rvc As ResourceVictoryCondition = vc
                        If rvc.TargetResourceType.Equals(res) Then Return False
                    End If
                Next
            Next

            Return True

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Function

    Private Function IsInstallationValidToDelete(ByRef inst As ObjectiveType) As Boolean
        Try

            '// we just need to check if any are deployed, if so, no delete.
            Dim gc As ChitMember

            For Each gc In ptrCGD.Chits
                If gc.UnitType = GroundChitClass_cgd.Objective Then
                    Dim instie As InstallationChit = gc
                    If instie.ptrInstallation.Equals(inst) Then Return False
                End If
            Next

            Return True

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Function

    Private Sub cboTurnLength_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTurnLength.SelectedIndexChanged
        Try
            Select Case cboTurnLength.Text
                Case Is = "Five Minutes" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FiveMinute
                Case Is = "Fifteen Minutes" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FifteenMinute
                Case Is = "Half Hour" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.HalfHour
                Case Is = "One Hour" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Hour
                Case Is = "Half Day" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.HalfDay
                Case Is = "One Day" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.FullDay
                Case Is = "One Week" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Week
                Case Is = "One Month" : ptrCGD.TurnLength = cmplib01.TurnLength_cgd.Month
            End Select
        Catch ex As Exception

        End Try
    End Sub
End Class
